package config

import (
	"booking/common/utils"
	"bytes"
	"embed"
	"github.com/gin-gonic/gin"
	"github.com/spf13/viper"
	"os"
)

//go:embed *.yaml
var configFs embed.FS

// Init 初始化配置项
func Init() {
	env := os.Getenv("PRO_ENV")
	if env == "" {
		env = "prod"
	}
	utils.InfoLog(env)
	viper.SetConfigType("yaml")
	data, readErr := configFs.ReadFile(env + ".yaml")
	if readErr != nil {
		utils.ErrorLog("读取配置文件失败: ", readErr)
	}
	if err := viper.ReadConfig(bytes.NewBuffer(data)); err != nil {
		utils.ErrorLog("解析配置文件失败: ", err)
	}
	ginMode := viper.GetString("gin.mode")
	gin.SetMode(ginMode)
}
